#include <stdio.h>

int main_27()
{
    int a,score=0,plus=0;
    while (scanf("%d",&a)!=EOF&&a)
    {
        score+=a;
        if (1==a)
        {
            plus=0;
        }else
        {
            score+=plus;
            plus+=2;
        }
    }
    printf("%d\n",score);
    return 0;
}

